package com.rssreader.client;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
import com.rssreader.client.components.ItemPanel;
import com.rssreader.client.components.NavPanel;
import com.rssreader.client.services.FeedService;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class CopyOfRSSReader implements EntryPoint {

    @Override
    public void onModuleLoad() {
	Registry.register(RSSReaderConstants.FEED_SERVICE,
		GWT.create(FeedService.class)); // 通過FeedService.class，得到了FeedServiceAsync
						// .class
	Registry.register(RSSReaderConstants.FEED_STORE, new ListStore<BeanModel>()); // ***一定要放前面，先宣告***

	Viewport viewport = new Viewport();
	final BorderLayout borderLayout = new BorderLayout(); // 新增一個BorderLayout並讓Viewport使用它
	viewport.setLayout(borderLayout);

	BorderLayoutData northData = new BorderLayoutData(LayoutRegion.NORTH, 20);
	northData.setCollapsible(false); // collapsible***一定要寫
	northData.setSplit(false); // resizable

	BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
	centerData.setCollapsible(false); // collapsible

	BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 200,
		150, 300);
	westData.setCollapsible(true); // collapsible
	westData.setSplit(true); // resizable

	HTML headerHtml = new HTML(); // create an HTML widget to use and add it
				      // to the viewport
	headerHtml.setHTML("<h1>RSS Reader</h1>");
	viewport.add(headerHtml, northData);

	// right-----------------------
	// RssMainPanel mainPanel = new RssMainPanel();
	ItemPanel mainPanel = new ItemPanel();
	mainPanel.displayItem(TestObjects.getTestItem());// 呈現的內容
	// left------------------------
	NavPanel navPanel = new NavPanel();

	viewport.add(mainPanel, centerData); // Panel, borderLayoutData
	viewport.add(navPanel, westData);

	RootPanel.get().add(viewport);
    }
}
